package com.etc.myblog.ser;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.etc.myblog.biz.ArticleBiz;
import com.etc.myblog.biz.ArticleCatBiz;
import com.etc.myblog.entity.Article;
import com.etc.myblog.entity.ArticleCat;

public class AdArticleSer extends HttpServlet {

	ArticleCatBiz artcleCatBiz = new ArticleCatBiz();
	ArticleBiz articleBiz = new ArticleBiz();
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request,response);
	}


	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		//获取分类
		List<ArticleCat> list = new ArrayList<ArticleCat>();
		list = artcleCatBiz.findAll();
    	request.setAttribute("articleCat", list);
    	request.setAttribute("adminName", "原子为");
		if(request.getParameter("op")!=null && request.getParameter("op")!=""){
			String op = request.getParameter("op");
			int id = Integer.parseInt(request.getParameter("id"));
			//审核通过
			if(op.equals("ArticlePass")){
				Article art = new Article();
				art = articleBiz.findByArticleId(id);
				art.setArticleStatus("审核通过");
				articleBiz.updateStatus(art);
			}
			else if(op.equals("ArticleNoPass")){
				Article art = new Article();
				art = articleBiz.findByArticleId(id);
				art.setArticleStatus("审核不通过");
				articleBiz.updateStatus(art);
			}
		}
		if(request.getParameter("sortId")!=null && request.getParameter("sortId")!=""){
			
			int id = Integer.parseInt(request.getParameter("sortId"));
			//审核通过
			
			List<Article> list1 = new ArrayList<Article>();
			list1 = articleBiz.findNoAdArticleBysortId(id);
			request.setAttribute("article", list1);
			request.getRequestDispatcher("admin/articleAdmin.jsp").forward(request, response);
			return;
		
		}	
        List<Article> list1 = new ArrayList<Article>();
        list1 = articleBiz.findNoAdArticle();
    	request.setAttribute("article", list1);      
		request.getRequestDispatcher("admin/articleAdmin.jsp").forward(request, response);
		
	}

}
